<?php

class Application_Form_AdminBet extends Zend_Form
{
	protected $_type;
	public function __construct($type=null){		
		$this->_type = $type;
		parent::__construct();
	}
	
    public function init()
    {
		$this->setMethod('post');
		$addElements = array();
        $editElements = array();
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Edit')
        		->setDecorators(array('ViewHelper', 'Description', 'Errors',
        		array(
        			array('data' => 'HtmlTag'), 
        			array('tag' => 'td', 'colspan'=>'4','align'=>'center')),
        		array(
        			array('row' => 'HtmlTag'),
        			array('tag' => 'tr'))
        			));
		$editElements[] = $bet_left = new Zend_Form_Element_Text('bet_left');
        $bet_left->setLabel('Bet left')
        		->setOptions(array('size' => 5))
        		->setRequired(true)
        		->addValidator('Int')
        		->addValidator('GreaterThan', false, array('min' => -1))
        		->setDecorators(array('ViewHelper', 'Description', 'Errors',
        		array(
        			array('data' => 'HtmlTag'), 
        			array('tag' => 'td')),
        		array(
        			'Label', 
        			array('tag' => 'td')),
        		array(
        			array('row' => 'HtmlTag'),
        			array('tag' => 'tr', 'openOnly' => 'true'))   
        			));
        $editElements[] = $bet_right = new Zend_Form_Element_Text('bet_right');
        $bet_right->setLabel('Bet right')
        		->setOptions(array('size' => 5))
        		->setRequired(true)
        		->addValidator('Int')
        		->addValidator('GreaterThan', false, array('min' => -1))
        		->setDecorators(array('ViewHelper', 'Description', 'Errors',
        		array(
        			array('data' => 'HtmlTag'), 
        			array('tag' => 'td')),
        		array(
        			'Label', 
        			array('tag' => 'td', 'placement' => 'append')),
        		array(
        			array('row' => 'HtmlTag'),
        			array('tag' => 'tr', 'closeOnly' => 'true'))
        			));
    	$editElements[] = $status = new Zend_Form_Element_Select('status');
		    $status->setLabel('Bet status')
		        	->addMultiOption('opened', 'opened')
		        	->addMultiOption('closed', 'closed')
		        	->setRequired(true)
		        	->addFilter('StripTags')
		        	->addFilter('StringTrim');
        if($this->_type == 'add'){
	        $addElements[] = $user = new Zend_Form_Element_Select('user_id');
	        $user->setLabel('User')
	        		->setRequired(true)
	        		->addValidator('Int')
	        		->addValidator('GreaterThan', false, array('min' => 0));
	        $addElements[] = $event = new Zend_Form_Element_Select('event_id');
	        $event->setLabel('Event')
	        		->setRequired(true)
	        		->addValidator('Int')
	        		->addValidator('GreaterThan', false, array('min' => 0));
			$submit->setLabel('Add');
        }

        $this->addElements($editElements);
        $this->addElements($addElements);        
        $this->addElement($submit);
        $this->setDecorators(array('FormElements',
        		array(
        			array('data'=>'HtmlTag'),array('tag'=>'table')),'Form'));
    }
    public function fillForm(){
    	$user = new Application_Model_User();
    	$users = $user->getAll();
    	foreach ($users as $u){
			$this->user_id->addMultiOption($u['id'], $u['name']);
		}
		$event = new Application_Model_Event();
		$events = $event->getAll(false, null, false);
        foreach ($events as $e){
			$this->event_id->addMultiOption($e['id'], $e['title']);
		}
    }
}

